package com.ops.service.ns.system.helper;


import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.Reference;

import com.ops.service.ns.system.constants.ParamConstants;



public class OPSJNDIContext
{
   
	private static Map<String,String> JNDI_CONFIG_MAP=null;
	private static final Logger LOG = Logger.getLogger(OPSJNDIContext.class.getName());
	
	
	public static void loadJNDI()
	{
		try
		{
            InitialContext initContext = new InitialContext();
			LOG.log(Level.INFO,"OPSJNDIContext->loadJNDI-> before loading JNDI parameters");
			Reference rs = (Reference) initContext.lookup(ParamConstants.OPS_SERVICE_SERVICE_URL);
			JNDI_CONFIG_MAP=new HashMap<String,String>();
			JNDI_CONFIG_MAP.put(ParamConstants.OPS_SERVICE_SERVICE_URL, (String)rs.get(0).getContent());
			
			
			System.out.println("JNDI Value is:"+JNDI_CONFIG_MAP.get(ParamConstants.OPS_SERVICE_SERVICE_URL));
			
			LOG.log(Level.INFO,"OPSJNDIContext->loadJNDI-> after loading JNDI parameters");
		}
		catch (NamingException ne) {
            LOG.log(Level.SEVERE, "OPSJNDIContext-> JNDI parameter reading exception ", ne);
        }
	}
		
	public static String getJNDIValue(String key)
	{
		if(key != null)
		{
			return (String)(JNDI_CONFIG_MAP.get(key));
		}
		return null;
	}
}

